USE SAS
GO

IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'GetResellerAccounts')
	BEGIN
		DROP  Procedure  dbo.GetResellerAccounts
	END

GO

CREATE Procedure dbo.GetResellerAccounts
	@isActive BIT = NULL
AS
BEGIN
	select 
		p.PartnerNo AS [Reseller No]
	,	p.PartnerName AS [Reseller Name]
	,	a.City
	,	a.State
	,	a.Zip as [Zip Code]
	,	c.Phone
	,	p.Website
	,	(CASE WHEN IsActive=1 THEN 'Yes' ELSE 'No' END) As Active
	,	p.PartnerGUID as [PKID]
	FROM dbo.TR_Partner as p with (NOLOCK)
	LEFT OUTER JOIN TR_ADDRESS as a with (NOLOCK)
		on a.PartnerGUID = p.PartnerGUID
	LEFT OUTER JOIN TR_COMMUNICATION as c WITH (NOLOCK)
		on c.AddressGUID = a.AddressGUID
	WHERE
		isActive = ISNULL(@isActive, isActive)
	AND	PartnerCategory = 2
	AND	PartnerType = 5
	ORDER BY
		isActive DESC,
		PartnerName ASC
END
GO
